/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interprete;

import interprete.Token.token;

/**
 *
 * @author lynx
 */
class PilaAritmeticaLogica {
    
    private PilaGenerica pila;

    PilaAritmeticaLogica() {
        pila = new PilaGenerica();
    }
    
    void mete(Token t){
        pila.Push(t);
    }
    
    Token saca(){
        return (Token) pila.Pop();
    }
    
    Token tope(){
        return (Token)pila.Top();
    }
        
    void asignación(){
        Token a, b;
        b = (Token) pila.Pop();
        a = (Token) pila.Pop();
        a.valor(b.valor());
        mete(a);
    }

    void suma(){
        Token a, b, c;
        a = (Token) pila.Pop();
        b = (Token) pila.Pop();
        c = new Token(token.LITERAL, null, a.valor()+b.valor());
        mete(c);
    }
    
    void resta(){
        Token a, b, c;
        b = (Token) pila.Pop();
        a = (Token) pila.Pop();
        c = new Token(token.LITERAL, null, a.valor()-b.valor());
        mete(c);
    }
    
    void multiplicación(){
        Token a, b, c;
        a = (Token) pila.Pop();
        b = (Token) pila.Pop();
        c = new Token(token.LITERAL, null, a.valor()*b.valor());
        mete(c);
    }
    
    void división(){
        Token a, b, c;
        b = (Token) pila.Pop();
        a = (Token) pila.Pop();
        c = new Token(token.LITERAL, null, a.valor()/b.valor());
        mete(c);
   }
    
    void menos(){
        Token a, b;
        a = (Token) pila.Pop();
        b = new Token(token.LITERAL, null, -a.valor());
        mete(b);
    }
    
    void mayor(){
        Token a, b, c;
        b = (Token) pila.Pop();
        a = (Token) pila.Pop();
        c = new Token(token.LITERAL, null, (a.valor()>b.valor()?1:0));
        mete(c);        
    }
    
    void mayorIgual(){
        Token a, b, c;
        b = (Token) pila.Pop();
        a = (Token) pila.Pop();
        c = new Token(token.LITERAL, null, (a.valor()>=b.valor()?1:0));
        mete(c);        
    }
    
    void menor(){
        Token a, b, c;
        b = (Token) pila.Pop();
        a = (Token) pila.Pop();
        c = new Token(token.LITERAL, null, (a.valor()<b.valor()?1:0));
        mete(c);        
    }
    
    void menorIgual(){
        Token a, b, c;
        b = (Token) pila.Pop();
        a = (Token) pila.Pop();
        c = new Token(token.LITERAL, null, (a.valor()<=b.valor()?1:0));
        mete(c);        
    }
    
    void igual(){
        Token a, b, c;
        b = (Token) pila.Pop();
        a = (Token) pila.Pop();
        c = new Token(token.LITERAL, null, (a.valor()==b.valor()?1:0));
        mete(c);        
    }
    
    void diferente(){
        Token a, b, c;
        b = (Token) pila.Pop();
        a = (Token) pila.Pop();
        c = new Token(token.LITERAL, null, (a.valor()!=b.valor()?1:0));
        mete(c);        
    }
    
    void y(){
        Token a, b, c;
        b = (Token) pila.Pop();
        a = (Token) pila.Pop();
        c = new Token(token.LITERAL, null, (a.valor()== 1 && b.valor()==1?1:0));
        mete(c);                
    }

    void o(){
        Token a, b, c;
        b = (Token) pila.Pop();
        a = (Token) pila.Pop();
        c = new Token(token.LITERAL, null, (a.valor()== 1 || b.valor()==1?1:0));
        mete(c);                
    }
    
    void no(){
        Token a, b;
        a = (Token) pila.Pop();
        b = new Token(token.LITERAL, null, (a.valor()== 1?0:1));
        mete(b);
    }
    
}
